package server;

import java.io.Serializable;
import java.util.Arrays;
/**
 * 代表客户端对服务器的请求.
 * 包含 SessionID, 和客户请求的方法封装
 *  */
public class Request implements Serializable {

  private static final long serialVersionUID = -1383039785243769665L;
  /** 使用UUID算法实现 */
  private String sessionId;
  //login(1001,"1234")
  //start()
  /** 方法名 */
  private String method; // "login"
  /** 参数类型列表 */
  private Class[] argsTypes;// int, String
  /** 方法 参数 */
  private Object[] args; // 1001, "1234"

  public Request() {
  }

  // new Request("login",
  // new Class[]{int.class, String.class})
  // new Request("login",
  // int.class, String.class);

  public Request(String method, Class... argsTypes) {
    this.method = method;
    this.argsTypes = argsTypes;
  }
  public Request(String method,Class[] argsTypes, Object[] args) {
	  this.method = method;
	  this.argsTypes = argsTypes;
	  this.args=args;
  }
  
  public Request(String sessionId, String method, Class[] argsTypes, Object[] args) {
    this.sessionId = sessionId;
    this.method = method;
    this.argsTypes = argsTypes;
    this.args = args;
  }

  public Class[] getArgsTypes() {
    return argsTypes;
  }

  public void setArgsTypes(Class... argsTypes) {
    this.argsTypes = argsTypes;
  }

  public String getMethod() {
    return method;
  }

  public void setMethod(String method) {
    this.method = method;
  }

  public Object[] getArgs() {
    return args;
  }

  public void setArgs(Object... args) {
    this.args = args;
  }

  public String getSessionId() {
    return sessionId;
  }

  public void setSessionId(String sessionId) {
    this.sessionId = sessionId;
  }

  @Override
  public String toString() {
    return sessionId + ":" + method + ":" + Arrays.toString(args);
  }
}
